// File: entity/ChapterInfo.h
#pragma once
#include <QObject>

class ChapterInfo : public QObject {

    //引入信号和槽宏
    Q_OBJECT

    //声明qml可用方法
    Q_PROPERTY(QString id READ getId WRITE setId NOTIFY idChanged)
    Q_PROPERTY(QString novelId READ getNovelId WRITE setNovelId NOTIFY novelIdChanged)
    Q_PROPERTY(QString title READ getTitle WRITE setTitle NOTIFY titleChanged)  // 重点修复这里
    Q_PROPERTY(int chapterIndex READ getChapterIndex WRITE setChapterIndex NOTIFY chapterIndexChanged)
    Q_PROPERTY(QString path READ getPath WRITE setPath NOTIFY pathChanged)
    Q_PROPERTY(int wordCount READ getWordCount WRITE setWordCount NOTIFY wordCountChanged)
    Q_PROPERTY(int startOffset READ getStartOffset WRITE setStartOffset NOTIFY startOffsetChanged)
    Q_PROPERTY(int endOffset READ getEndOffset WRITE setEndOffset NOTIFY endOffsetChanged)
    Q_PROPERTY(QString prevChapter READ getPrevChapter WRITE setPrevChapter NOTIFY prevChapterChanged)
    Q_PROPERTY(QString nextChapter READ getNextChapter WRITE setNextChapter NOTIFY nextChapterChanged)
    Q_PROPERTY(int loadStatus READ getLoadStatus WRITE setLoadStatus NOTIFY loadStatusChanged)
    Q_PROPERTY(int status READ getStatus WRITE setStatus NOTIFY statusChanged)


    //定义构造函数和getter与setter
    public:
        explicit ChapterInfo(QObject *parent = nullptr);

        // Getters
        QString getId() const;
        QString getNovelId() const;
        QString getTitle() const;
        int getChapterIndex() const;
        QString getPath() const;
        int getWordCount() const;
        int getStartOffset() const;
        int getEndOffset() const;
        QString getPrevChapter() const;
        QString getNextChapter() const;
        int getLoadStatus() const;
        int getStatus() const;
        QString toString() const;

        // Setters
        void setId(const QString &id);
        void setNovelId(const QString &novelId);
        void setTitle(const QString &title);
        void setChapterIndex(int chapterIndex);
        void setPath(const QString &path);
        void setWordCount(int wordCount);
        void setStartOffset(int startOffset);
        void setEndOffset(int endOffset);
        void setPrevChapter(const QString &prevChapter);
        void setNextChapter(const QString &nextChapter);
        void setLoadStatus(int loadStatus);
        void setStatus(int status);

        // 声明所有 NOTIFY 信号
        signals:
            void idChanged();
            void novelIdChanged();
            void titleChanged();  // title 对应的信号
            void chapterIndexChanged();
            void pathChanged();
            void wordCountChanged();
            void startOffsetChanged();
            void endOffsetChanged();
            void prevChapterChanged();
            void nextChapterChanged();
            void loadStatusChanged();
            void statusChanged();

    //定义属性
    private:
        //章节id
        QString id;

        //小说id
        QString novelId;

        //章节标题
        QString title;

        //章节索引
        int chapterIndex;

        //章节路径，使用章节名字作为MD5
        QString path;

        //章节字数
        int wordCount;

        //开始偏移量
        int startOffset;

        //结束偏移量
        int endOffset;

        //上一章节id
        QString prevChapter;

        //下一章节id
        QString nextChapter;

        //加载状态：0未加载，1加载完成
        int loadStatus;

        //状态：0未读，1阅读中，2阅读完
        int status;
};
